﻿//
// Copyright (c) 2024 BPer
//

#ifndef SRC_BPERRTC_BPERBANDWIDTH_H_
#define SRC_BPERRTC_BPERBANDWIDTH_H_

#include <bperrtc/BPerRtcTwcc.h>
#include <bperrtc/BPerRtcStats.h>
#include <bperutil/BPerAvcType.h>

#define BPer_LostRate_defaultCount 5

typedef enum{
	BPerLowLostRate,
	BPerHighLostRate
}BPerLostRateState;

typedef struct{
	int32_t hightLostCount;
	int32_t lowLostCount;
	int32_t lastCheckSn;
	int32_t preCheckSn;
	int32_t lossPacketCount;
	//BPerRequestType request;
	//uint64_t lastPacketCount;

	double lostRate;

	BPerLostRateState lostRateState;
	BPerLostRateState preLostRateState;

}BPerBandwidthSession;

typedef struct{
	BPerBandwidthSession session;
	int32_t (*estimate)(BPerBandwidthSession* bw,BPerTwccSession* twcc);
	int32_t (*checkByTwcc)(BPerBandwidthSession* bw,BPerTwccSession* twcc);
	int32_t (*checkBandWidth)(BPerBandwidthSession* bw,BPerRtcStats* stats,BPerStreamConfig* streamconfig,uint32_t ssrc);
}BPerBandwidth;

void bPer_create_bandwidth(BPerBandwidth* bw);
void bPer_destroy_bandwidth(BPerBandwidth* bw);

#endif /* SRC_BPERRTC_BPERBANDWIDTH_H_ */
